package com.fesine.ch02.synBlockString;

/**
 * @description: 对象监视器必须是同一个对象，否则就又是异步调用
 * @author: Fesine
 * @createTime:2016/7/4 19:05
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/7/4 19:05
 */
public class Service {
    private String usernameParam;
    private String passwordParam;
    private String anyString = new String();

    public void setUsernamePassword(String username, String password) {
        try {
            synchronized (anyString) {
                System.out.println("线程名称为："+Thread.currentThread().getName()+"在"+
                        System.currentTimeMillis()+"进入同步块");
                usernameParam = username;
                Thread.sleep(3000);
                passwordParam = password;
                System.out.println("线程名称为："+Thread.currentThread().getName()+"在"+
                        System.currentTimeMillis()+"离开同步块");
            }

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
